//---------------------------------------------------------------------------

#ifndef MyUtilityH
#define MyUtilityH
#define UTILITY_VERSION 0x20
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#define NO_DEBUG			0x1000
#define INFO_DEBUG		0x1003
#define DETAIL_DEBUG	0x1004
#define VERBOSE_DEBUG	0x1005
#define FULL_DEBUG		0x1006
#define WARNING_DEBUG	0x1001
#define ERROR_DEBUG		0x1002
//---------------------------------------------------------------------------
#define UTILITY_CORRECT		0x0000
//---------------------------------------------------------------------------
#define MAX_DEBUG_MESSAGE	100
#define MY_NEWLINE          "\n"
//---------------------------------------------------------------------------
#ifndef MY_BORLAND
	#ifdef __BORLANDC__
	#define MY_BORLAND
	#endif
#endif
#ifdef MY_BORLAND
#include <SysUtils.hpp>
#include <Classes.hpp>
#else
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#endif
#include <stdio.h>
#include <list>
#include <iostream>

using namespace std;

//---------------------------------------------------------------------------
typedef unsigned char MyUCHAR;
typedef struct{
	DWORD Level;
	char *Msg;
}Debug_Info;
//---------------------------------------------------------------------------
class MyUtility
{
private:
	int DebugMsgCount;
	int GetByteValue(char Value);
	unsigned char* InternalBuffer;
	bool isValidByte(unsigned char Value);
	char* InternalChar;
	wchar_t* InternalWChar;
	int FUtilityVersion;
	char* DumpByte(void *Buff, int Size);
	char* InternalDumpRow(void *Buff, int Size);
protected:
	virtual void DummyErrEvt(DWORD Code, DWORD SubCode, void*Add_Data);
	virtual void DummyWarnEvt(DWORD Code, DWORD SubCode, void *Add_Data);
	virtual void DummyDebugMsg(DWORD Level, char *Msg);
	void SetDebugLevel(int val);
	int GetDebugLevel();
	int GetUtilityVersion();	
	int FDebugLevel;
public:
	char* GetErrorDesc(DWORD Error);
	wchar_t* char_to_wchar(char* Input);
	char* wchar_to_char(wchar_t* Input);
	DWORD LogToFile(char *FileName, char *Msg);
	char* FormattedNow(char *PreNow, char *PostNow);
	char* GetNow(void);
	void *TextToBuffer(char *Src, int *Len);
	char* DumpRow(void *Buffer, int BufferLen);
	char* DumpBuffer(void *Buffer, int BufferLen, char *Preamble, bool ShowBytes);
#ifdef MY_BORLAND	
	void (__closure *OnDebugMsg)(DWORD Level, char *Msg);
	void (__closure *OnWarningEvt)(DWORD Code, DWORD SubCode, void*Add_Data);
	void (__closure *OnErrorEvt)(DWORD Code, DWORD SubCode, void*Add_Data);
#else
	virtual void OnDebugMsg(DWORD Level, char *Msg);
	virtual void OnWarningEvt(DWORD Code, DWORD SubCode, void*Add_Data);
	virtual void OnErrorEvt(DWORD Code, DWORD SubCode, void*Add_Data);
#endif
	list <char*>DebugMessage;
#ifdef MY_BORLAND	
	__property int DebugLevel = {read=GetDebugLevel, write=SetDebugLevel};
	__property int Version = {read=GetUtilityVersion};
#endif
	 MyUtility();
	void FormatDebugMsg(DWORD Level,char *Format,...);
	void FormatLogToFile(char *File,char *Format,...);
	int My_atoi(char *Val);
	char *CurrentDirectory();
	char *MyMoveFile(char *SrcFile, char *DirDest);
	char *DuplicateString(char *Src);
	char *GenerateString(char *Format,...);
	char *ExtractDirFromFile(char *FileName);
	char *GetCurrentAppDirectory();
};
//---------------------------------------------------------------------------
#endif
